<template>

  <el-cascader
    :value="value"
    :props="defaultProps"
    :options="options"
    @change="handleChange"
  />
</template>

<script>
import { getDepartment } from '@/api/department'
import { arrToTree } from '@/utils/index'
export default {
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      defaultProps: {
        value: 'id',
        label: 'name'
      },
      options: []
    }
  },
  created() {
    this.loadDepartment()
  },
  methods: {
    async loadDepartment() {
      const res = await getDepartment()

      this.options = arrToTree(res.data, 0)
    },
    handleChange(value) {
      const id = value[value.length - 1]
      this.$emit('input', id)
    }
  }
}
</script>

<style>

</style>
